home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Magazine / Online / MagPLIP / source / magplip.h < prev    next >
C/C++ Source or Header  |  1998-04-01  |  13KB  |  368 lines

  1. #ifndef __MAGPLIP_H
  2. #define __MAGPLIP_H
  3. /*
  4. ** $VER: magplip.h 1.15 (01 Apr 1998)
  5. **
  6. ** magplip.device - Parallel Line Internet Protocol
  7. **
  8. ** Original code written by Oliver Wagner and Michael Balzer.
  9. **
  10. ** This version has been completely reworked by Marius Gröger,
  11. ** introducing slight protocol changes. The new source is
  12. ** a lot better organized and maintainable.
  13. **
  14. ** Additional changes and code cleanup by Jan Kratochvil and Martin Mares.
  15. ** The new source is significantly faster and yet better maintainable.
  16. **
  17. ** (C) Copyright 1993-1994 Oliver Wagner & Michael Balzer
  18. ** (C) Copyright 1995 Jan Kratochvil & Martin Mares
  19. ** (C) Copyright 1995 Marius Gröger
  20. **     All Rights Reserved
  21. **
  22. ** $HISTORY:
  23. **
  24. ** 01 Apr 1998 : 001.015 :  intergated linPLIP modifications from Stephane
  25. ** 10 Apr 1996 : 001.014 :  + PLIPF_REPLYSS didn't fit into byte
  26. **                          + pb_ExtFlags
  27. ** 09 Apr 1996 : 001.013 :  added TrackRe.tr_Count
  28. ** 29 Mar 1996 : 001.012 :  changed copyright note
  29. ** 30 Dec 1995 : 001.011 :  + single dynamic frame buffer
  30. **                          + added a lot of min/max constants
  31. ** 29 Dec 1995 : 001.010 :  + pb_Startup
  32. **                          + new flag PLIPF_REPLYSS
  33. ** 03 Sep 1995 : 001.009 :  + removed PLIP(F|B)_SIDEA
  34. **                          + hardware addressing fields in PLIPBase
  35. ** 30 Aug 1995 : 001.008 :  support for timer-timed timeout :-)
  36. **                          some pecularities moved to compiler.h
  37. ** 13 Aug 1995 : 001.007 :  code cleanup
  38. ** 29 Jul 1995 : 001.006 :  support for arbitration delay
  39. ** 24 Jul 1995 : 001.005 :  only one delay value in config
  40. **                          some volatile elements in GD
  41. ** 25 Apr 1995 : 001.004 :  #define's FAR
  42. ** 06 Mar 1995 : 001.003 :  added collision delays
  43. ** 04 Mar 1995 : 001.002 :  packet-type now ULONG
  44. ** 18 Feb 1995 : 001.001 :  some SAS/C wrappers, better data base handling
  45. ** 12 Feb 1995 : 001.000 :  reworked original
  46. */
  47.  
  48.    /* system header files */
  49. #ifndef DEVICES_SANA2_H
  50. #include <devices/sana2.h>
  51. #endif
  52. #ifndef EXEC_SEMAPHORES_H
  53. #include <exec/semaphores.h>
  54. #endif
  55. #ifndef EXEC_LISTS_H
  56. #include <exec/lists.h>
  57. #endif
  58. #ifndef EXEC_INTERRUPTS_H
  59. #include <exec/interrupts.h>
  60. #endif
  61. #ifndef EXEC_LIBRARIES_H
  62. #include <exec/libraries.h>
  63. #endif
  64. #ifndef DOS_DOS_H
  65. #include <dos/dos.h>
  66. #endif
  67.  
  68. #ifndef __COMPILER_H
  69. #include "compiler.h"
  70. #endif
  71.  
  72.  
  73. /****************************************************************************/
  74.  
  75.  
  76.    /* memory economy is *everything* :-) */
  77. #define SERVERTASKNAME           pb->pb_DevNode.lib_Node.ln_Name
  78.  
  79.       /* default values */
  80. #define PLIP_DEFMTU              1024
  81. #define PLIP_DEFBPS              100000
  82. #define PLIP_DEFRETRIES          32
  83. #define PLIP_DEFTIMEOUT          (500*1000)
  84. #define PLIP_DEFDELAY            0
  85. #define PLIP_DELAYDIFF           2000
  86. #define PLIP_DEFARBITRATIONDELAY 500
  87.  
  88.       /* minimum values */
  89. #define PLIP_MINPRIORITY         -128
  90. #define PLIP_MINMTU              256
  91. #define PLIP_MINRETRIES          1
  92. #define PLIP_MINCOLLISIONDELAY   0
  93. #define PLIP_MINARBITRATIONDELAY 0
  94. #define PLIP_MINTIMEOUT          500
  95. #define PLIP_MINBPS              1
  96.  
  97.       /* maximum values */
  98. #define PLIP_MAXMTU              (128 * 1024)
  99. #define PLIP_MAXRETRIES          127   /* don't try higher values! */
  100. #define PLIP_MAXPRIORITY         127
  101. #define PLIP_MAXCOLLISIONDELAY   999999
  102. #define PLIP_MAXARBITRATIONDELAY 999999
  103. #define PLIP_MAXTIMEOUT          999999
  104. #define PLIP_MAXBPS              0x7fffffff
  105.  
  106. #ifdef LINPLIP
  107. #define PLIP_ADDRFIELDSIZE       0
  108. #else
  109.    /* magPLIPs hardware address: log2(two systems) = 1 */
  110. #define PLIP_ADDRFIELDSIZE       1
  111. #endif
  112.  
  113. /****************************************************************************/
  114.  
  115. #ifdef LINPLIP
  116.  
  117. /* Pseudo-ethernet frame used by the linux implementation of plip.
  118.  * The address are ignored by both end and never set from this side
  119.  */
  120. #define ETH_ALEN                6
  121.  
  122.  
  123. #define PKTFRAMESIZE_1           sizeof(SHORT)        /* packet-size */
  124. #define PKTFRAMESIZE_2           (sizeof(UWORD)+2*ETH_ALEN)       /* addresses and packet type */
  125.  
  126. struct PLIPFrame {
  127.    SHORT    pf_Size;
  128.    UBYTE    pf_DstAddr[ETH_ALEN], pf_SrcAddr[ETH_ALEN];
  129.    UWORD    pf_Type;
  130.    /*UBYTE    pf_Data[MTU];*/
  131.    /*UBYTE crc */
  132. };
  133.  
  134. #else /* original MAGPLIP */
  135.  
  136.    /* this _is_ awful, I know */
  137. #define PKTFRAMESIZE_1           4        /* the sync-field and packet-size */
  138. #define PKTFRAMESIZE_2           6                   /* crc and packet type */
  139.  
  140. struct PLIPFrame {
  141.    USHORT   pf_Sync;
  142.    SHORT    pf_Size;
  143.    USHORT   pf_CRC;
  144.    ULONG    pf_Type;
  145.    /*UBYTE    pf_Data[MTU];*/
  146. };
  147.  
  148.  
  149. #define SYNCBYTE_HEAD   0x42
  150. #define SYNCBYTE_CRC    0x01
  151. #define SYNCBYTE_NOCRC  0x02
  152. #define SYNCWORD_CRC    ((SYNCBYTE_HEAD << 8) | SYNCBYTE_CRC)
  153. #define SYNCWORD_NOCRC  ((SYNCBYTE_HEAD << 8) | SYNCBYTE_NOCRC)
  154.  
  155. #endif /* LINPLIP */
  156.  
  157. /****************************************************************************/
  158.  
  159.  
  160. struct TrackRec {
  161.    struct MinNode              tr_Link;
  162.    ULONG                       tr_PacketType;
  163.    ULONG                       tr_Count;
  164.    struct Sana2PacketTypeStats tr_Sana2PacketTypeStats;
  165. };
  166.  
  167.  
  168. /****************************************************************************/
  169.  
  170.  
  171. typedef BOOL (* ASM BMFunc)(REG(a0) void *, REG(a1) void *, REG(d0) LONG);
  172.  
  173. struct BufferManagement
  174. {
  175.     struct MinNode   bm_Node;
  176.     BMFunc           bm_CopyFromBuffer;
  177.     BMFunc           bm_CopyToBuffer;
  178. };
  179.  
  180.  
  181. /****************************************************************************/
  182.  
  183.  
  184.    /*
  185.    ** sent to the server task after being CreateNewProc()ed
  186.    */
  187. struct ServerStartup
  188. {
  189.    struct Message    ss_Msg;
  190.    struct PLIPBase  *ss_PLIPBase;
  191.    BOOL              ss_Error;
  192.    UBYTE             ss_Pad[2];
  193. };
  194.  
  195.  
  196.  
  197. /****************************************************************************/
  198.  
  199.  
  200. enum { S2SS_TXERRORS, S2SS_COLLISIONS, S2SS_COUNT };
  201.  
  202.  
  203.    /*
  204.    ** This count will record the number of packets that failed
  205.    ** to be transmitted.
  206.    */
  207. #define S2SS_PLIP_TXERRORS ((((S2WireType_PLIP) & 0xffff) << 16) | (S2SS_TXERRORS))
  208.  
  209.    /*
  210.    ** This count will record the number of line arbitration collisions
  211.    */
  212. #define S2SS_PLIP_COLLISIONS ((((S2WireType_PLIP) & 0xffff) << 16) | (S2SS_COLLISIONS))
  213.  
  214.  
  215. /****************************************************************************/
  216.  
  217.  
  218. struct PLIPBase
  219. {
  220.    struct Library              pb_DevNode;        /* basic device structure */
  221.    UBYTE                       pb_Unit;         /* unit of 1st OpenDevice() */
  222.    UBYTE                       pb_pad1; /* make the following long alligned */
  223.    BPTR                        pb_SegList;               /* pointer to code */
  224.    struct Library          *   pb_MiscBase,          /* various libs & res. */
  225.                *   pb_CIAABase,
  226.                *   pb_UtilityBase,
  227.                *   pb_TimerBase,
  228.                *   pb_DOSBase,
  229.                *   pb_SysBase;
  230.    struct ServerStartup    *   pb_Startup;            /* main server proces */
  231.    struct Process          *   pb_Server;             /* main server proces */
  232.    struct Task             *   pb_Task;         /* used for server shutdown */
  233.    struct Interrupt            pb_Interrupt;          /* for AddICRVector() */
  234.    ULONG                       pb_IntSig;        /* sent from int to server */
  235.    ULONG                       pb_IntSigMask;                  /* for speed */
  236.    ULONG                       pb_ServerStoppedSigMask;     /* for shutdown */
  237.    struct MsgPort          *   pb_ServerPort,       /* for IOReq forwarding */
  238.                *   pb_TimeoutPort,      /* for timeout handling */
  239.                *   pb_CollPort;       /* for collision handling */
  240.    struct timerequest          pb_TimeoutReq,       /* for timeout handling */
  241.                    pb_CollReq;        /* for collision handling */
  242.    struct Sana2DeviceStats     pb_DevStats;            /* SANA-2 wants this */
  243.    struct Sana2SpecialStatRecord
  244.                    pb_SpecialStats[S2SS_COUNT];
  245.    volatile struct List        pb_ReadList,                  /* the readers */
  246.                    pb_WriteList,                 /* the writers */
  247.                    pb_EventList,              /* event tracking */
  248.                    pb_ReadOrphanList,   /* for spurious packets */
  249.                    pb_TrackList,                  /* track type */
  250.                    pb_BufferManagement;          /* Copy-In/Out */
  251.    struct SignalSemaphore      pb_EventListSem,     /* protection for lists */
  252.                    pb_ReadListSem,
  253.                    pb_WriteListSem,
  254.                    pb_TrackListSem,
  255.                    pb_ReadOrphanListSem,
  256.                    pb_Lock;
  257.    ULONG                       pb_Retries;                 /* config values */
  258.    ULONG                       pb_ReportBPS;
  259.    ULONG                       pb_MTU;
  260.    ULONG                       pb_AllocFlags;
  261.    ULONG                       pb_Timeout;
  262.    LONG                        pb_CollisionDelay;
  263.    LONG                        pb_ArbitrationDelay;
  264.    volatile UBYTE              pb_TimeoutSet;/* if != 0, a timeout occurred */
  265.    volatile UBYTE              pb_Flags;                       /* see below */
  266.    volatile UWORD              pb_ExtFlags;                    /* see below */
  267.    APTR                        pb_OldExceptCode;
  268.    APTR                        pb_OldExceptData;
  269.    ULONG                       pb_OldExcept;
  270. #ifndef LINPLIP
  271.    UBYTE                       pb_HandshakeMask[2],   /* crossed for side-a */
  272.                    pb_HandshakeBit[2];            /* and side-b */
  273.    UBYTE                       pb_SrcAddr[PLIP_ADDRFIELDSIZE];
  274.    UBYTE                       pb_DstAddr[PLIP_ADDRFIELDSIZE];
  275. #endif
  276.    struct PLIPFrame        *   pb_Frame;
  277. };
  278.  
  279.    /*
  280.    ** used as index for PLIPBase->pb_HandshakeMask[]/pb_HandshakeBit[]
  281.    */
  282. #define HS_LINE        0   /* as we use compatible plip wireing, our magic */
  283. #define HS_REQUEST     1   /* is to cross the lines transparently by software */
  284.  
  285. #ifdef __SASC
  286.      /*
  287.      ** redirect all shared library bases to our device base.
  288.      */
  289. #  define SysBase      pb->pb_SysBase
  290. #  define DOSBase      pb->pb_DOSBase
  291. #  define TimeBase     pb->pb_TimeBase
  292. #  define UtilityBase  pb->pb_UtilityBase
  293. #  define MiscBase     pb->pb_MiscBase
  294. #  define CIAABase     pb->pb_CIAABase
  295. #  define CiaBase      pb->pb_CIAABase
  296. #  define TimerBase    pb->pb_TimerBase
  297.      /*
  298.      ** This macro declares a local variable which temporary gets
  299.      ** SysBase directly from AbsExecBase.
  300.      */
  301. #  define LOCALSYSBASE struct { void *pb_SysBase; } *pb = (void*)0x4
  302.      /*
  303.      ** Use this macro as argument for all functions which need to
  304.      ** have access to your data base.
  305.      */
  306. #  define BASEPTR      struct PLIPBase *pb
  307. #else
  308. #  error Please define library bases for your compiler
  309. #endif
  310.  
  311.    /*
  312.    ** Values for PLIPBase->pb_Flags
  313.    ** Note that the Flags field is intentionally only 8 bits wide so that
  314.    ** the ASM parts may use the bit functions.
  315.    */
  316. #define PLIPB_REPLYSS         0   /* server-startup must be replied */
  317. #define PLIPB_EXCLUSIVE       1   /* current opener is exclusive */
  318. #define PLIPB_NOTCONFIGURED   2   /* not configured */
  319. #define PLIPB_OFFLINE         3   /* currently not online (sic!) */
  320. #define PLIPB_SENDCRC         4   /* send with CRC sum */
  321. #define PLIPB_RECEIVING       5   /* set by interrupt */
  322. #define PLIPB_COLLISION       6   /* arbitration detected a collision */
  323. #define PLIPB_SERVERSTOPPED   7   /* set by server while passing away */
  324.  
  325. #define PLIPF_EXCLUSIVE       (1<<PLIPB_EXCLUSIVE)
  326. #define PLIPF_NOTCONFIGURED   (1<<PLIPB_NOTCONFIGURED)
  327. #define PLIPF_OFFLINE         (1<<PLIPB_OFFLINE)
  328. #define PLIPF_SENDCRC         (1<<PLIPB_SENDCRC)
  329. #define PLIPF_RECEIVING       (1<<PLIPB_RECEIVING)
  330. #define PLIPF_COLLISION       (1<<PLIPB_COLLISION)
  331. #define PLIPF_SERVERSTOPPED   (1<<PLIPB_SERVERSTOPPED)
  332. #define PLIPF_REPLYSS         (1<<PLIPB_REPLYSS)
  333.  
  334.    /*
  335.    ** Values for PLIPBase->pb_ExtFlags
  336.    */
  337. #define PLIPEB_NOSPECIALSTATS 0   /* don't report special stats */
  338. #define PLIPEB_NIBBLEACK      1   /* Used only in linplip.asm */
  339.  
  340. #define PLIPEF_NOSPECIALSTATS (1<<PLIPEB_NOSPECIALSTATS)
  341. #define PLIPEF_NIBBLEACK      (1<<PLIPEB_NIBBLEACK)
  342.  
  343.  
  344. /****************************************************************************/
  345.  
  346.  
  347.    /*
  348.    ** configuration stuff
  349.    */
  350. #define CONFIGFILE "ENV:SANA2/magPLIP.config"
  351.  
  352. #define TEMPLATE "TIMEOUT/K/N,PRIORITY=PRI/K/N,MTU/K/N,BPS/K/N,RETRIES/K/N,SENDCRC/S,CD=COLLISIONDELAY/K/N,AD=ARBITRATIONDELAY/K/N,NOSPECIALSTATS/S"
  353.  
  354. struct PLIPConfig
  355. {
  356.       ULONG *timeout;
  357.       LONG  *priority;
  358.       LONG  *mtu;
  359.       LONG  *bps;
  360.       LONG  *retries;
  361.       ULONG  sendcrc;
  362.       LONG  *collisiondelay;
  363.       LONG  *arbitrationdelay;
  364.       ULONG  nospecialstats;
  365. };
  366.  
  367. #endif
  368.